(function (Vue: any, Mescroll: any, axios: any, undefined) {
  let goods = [
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    },
    {
      avatar: 'http://59.110.173.105/20171122144637.png',
      title: '爱儿美儿童摄影（洋桥店）',
      address: '洋桥／木樨园 2.3km',
      price: '580',
      originalPrice: '620'
    }
  ];
  new Vue({
    el: '#app',
    data: {
      message: '123',
      goods: [],
      mescroll: null,
      page: {
        num: 1,
        size: 3
      }
    },
    methods: {
      getData(pageNum: number, pageSize: number, callback: any, errCallback: any) {
        setTimeout(() => {
          let data = goods
          let dataList = []
          for (let i = (pageNum - 1) * pageSize;i < pageNum * pageSize;i++) {
            if (i == data.length) break
            dataList.push(data[i])
          }
          callback && callback(dataList)
        }, 500);
      },
      upCallback(page: any) {
        let self: any = this
        // 去获取数据page会自动增加数值
        this.getData(page.num, page.size, function (curPageData: any) {
          // 如果为第一页则清空防止重复增加数据
          page.num == 1 && (self.goods = [])

          // 更新数据列表
          self.goods = self.goods.concat(curPageData)
          // 显示请求
          console.log("page.num=" + page.num + ", page.size=" + page.size + ", curPageData.length=" + curPageData.length +
            ", self.goods.length==" + self.goods.length);
          // 如果返回的数据没有更多则显示提示
          self.mescroll.endSuccess(curPageData.length)
        }, function () {
          self.mescroll.endErr()
        })
      }
    },
    mounted() {
      let self = this
      self.mescroll = new Mescroll("mescroll", {
        down: {
          isLock: true,
        },
        up: {
          // auto: false,
          callback: self.upCallback,
          page: {
            size: 4
          }
        }
      })
    }
  })
}(Vue, MeScroll, axios))

